package com.gitee.wsl.struct.grammar.ast.process.constraints


import com.gitee.wsl.text.reader.line.LookaheadText

/**
 * A generalized "indent" in markdown world. Stores types of blocks spawning indents alongside indents themselves.
 */
interface TextReadConstraints {

    val indent: Int

    val types: CharArray

    val isExplicit: BooleanArray

    val charsEaten: Int

    /**
     * Whether another constraints can "continue" opened blocks corresponding to {@code this} constraints
     */
    fun startsWith(other: TextReadConstraints): Boolean

    /**
     * Leaking abstraction: whether there are "breaking" modifiers which do not continue other constraints
     * even if all types and indents are correct. In fact, means whether there are list markers or not.
     */
    fun containsListMarkers(upToIndex: Int): Boolean

    /**
     * Return new constraints with a new modifier added or {@code null} if position does not add new modifiers
     */
    fun addModifierIfNeeded(pos: LookaheadText.Position?): TextReadConstraints?

    /**
     * Returns a constraints for the next line (at given pos) by continuing as much as possible from {@code this}
     * constraints without adding any new modifiers
     */
    fun applyToNextLine(pos: LookaheadText.Position?): TextReadConstraints
}

